

<?php
$this->db->where('car_type_id', 1);
$cardname1 = $this->db->get('tbl_card');
$this->db->where('car_type_id', 2);
$cardname2 = $this->db->get('tbl_card');
$option1 = "";
$option2 = "";
$option1.='<option value="">-Please select-</option>';
foreach ($cardname1->result() as $value) {
    $option1.='<option value="' . $value->car_id . '">' . $value->car_name . '</option>';
}
$option2.='<option value="">-Please select-</option>';
foreach ($cardname2->result() as $values) {
    $option2.='<option value="' . $values->car_id . '">' . $values->car_name . '</option>';
}

$this->db->where('price_K');
$prcekhmer = $this->db->get('tbl_pricecard');
?>
<style type="text/css">
    fieldset {
        display: none;
        margin: 10px; 
    }
    span{ color:red;}
</style>

<div style="margin: 0 auto;width: 98%;height: auto;border: 0px #ccc solid;text-align: center;font-size: 20px;color:#006600;">Edit Card Sale</div><br/>
<div style="margin: 0 auto;width:60%;height: auto;border: 1px #ccc solid; padding:20px 15px 20px 15px;-moz-border-radius:10px;">
    <div style="float: right; border: 0px #ccc solid;"><?php echo anchor('sale_management/sale_card', img('images/user_images/cancel.png')); ?></div>
    <?php echo form_open('sale_management/edit_salecard/' . $this->uri->segment('3'), array('method' => 'post')); ?>
    <?php
    foreach ($cardvalue->result() as $value) {
        echo '<table border="0" align="center" style="font-weight: lighter;font-size: 14px; celspacing="0" cellpadding="3" height="auto">';
        echo '<tr>';
        $query_student = $this->db->query('SELECT * from tbl_student');
        echo '<td>Customer Name<span>*</span></td>';
        echo '<td>';
        $select = '<select name="student" id="student">';
        $select.='<option value="0">--Select Customer Name--</option>';
        foreach ($query_student->result() as $rows) {
            $cust_name = ($value->stu_id == $rows->stu_id) ? ' selected="selected"' : '';
            $select.='<option value="' . $rows->stu_id . '"' . $cust_name . '>' . $rows->stu_name . '</option>';
        }
        $select.='</select>';
        echo $select;
        echo'</td>';
        echo '</tr>';
        echo '</tr>';
        echo '<tr>';
        $query_cardType = $this->db->query('SELECT * from tbl_car_type');
        echo '<td>Card Type</td>';
        echo '<td>';
        $select = '<select name="card_type" id="type">';
        $select.='<option value="0">--Select Card Type--</option>';
        foreach ($query_cardType->result() as $row) {
            $card_type = ($value->car_type_id == $row->car_type_id) ? ' selected="selected"' : '';
            $select.='<option value="' . $row->car_type_id . '"' . $card_type . '>' . $row->car_type_name . '</option>';
        }
        $select.='</select>';
        echo $select;
        echo '</td></tr>';
        echo '<tr>';
        echo '<td>Card Name</td>';
        echo '<td>';
        $select = '<select name="card" id="card">';
        $name = $this->db->get('tbl_card');
        $select.='<option value="0">--Select--</option>';
        foreach ($name->result() as $namecard) {
            $card_name = ($value->car_id == $namecard->car_id) ? ' selected="selected"' : '';
            $select.='<option value="' . $value->car_id . '"' . $card_name . '>' . $value->car_name . '</option>';
        }
        $select.='</select>';
        echo $select;
        echo'</td></tr>';
        echo '<td>Price Card <span>*</span>$</td>';
        //  foreach ($data->result() as $value){
        echo '<td>' . form_input(array('name' => 'txt_price', 'id' => 'txt_price', 'readonly' => '', 'value' => $value->sal_price)) . '</td>';
        echo '<tr>';
        echo '<td>Sale Quantity</td>';
        echo '<td>' . form_input(array('name' => 'txt_quantity', 'value' => $value->sal_quantity)) . '</td>';
        echo '</tr>';
        echo '<tr>';
        echo '<td>Payment $</td>';
        echo '<td>' . form_input(array('name' => 'txt_payment', 'value' => $value->sal_payment)) . '</td>';
        echo '</tr>';
        //----------------------edit date=====================/
        echo '<tr>';
        echo '<td>SaleDate<span>*</span></td>';
        echo '<td>';
        echo form_input(array('name' => 'txt_saleDate', 'class' => 'datepicker', 'value' => $value->sal_date));
        echo '</td>';
        echo '</tr>';
        echo '<tr>';
        echo '<td>Descripton</td>';
        echo '<td> ' . form_textarea(array('name' => 'txt_description', 'rows' => '8', 'cols' => '50', 'value' => $value->sal_description)) . '</td>';
        echo'</tr>';
    }
    echo '<tr>';
    echo '<td></td>';
    echo '<td>' . form_input(array('name' => 'btn_update', 'type' => 'submit', 'value' => 'Update')) . form_input(array('type' => 'reset', 'value' => 'Reset')) . '</td>';
    echo '</tr></table>';
    ?>
    <?php echo form_close(); ?>
</div>

<script type="text/javascript">
    $(function(){

        $(function(){
            $('#type').change(function(){
                var typ_id = $(this).val();

                $.ajax({
                    type: 'POST',
                    url: "<?php echo base_url() . 'sale_management/getCardByType'; ?>",
                    data: {
                        type_id: typ_id
                    },
                    success: function(opt){

                        $('#card').html(opt);

                    }
                });
            });
        });

        $(function(){
            $('#card').change(function(){
                var card_id = $(this).val();
                var stu_id = $('#student').val();
                $.ajax({
                    type: 'POST',
                    url: "<?php echo base_url() . 'sale_management/getCardPrice'; ?>",
                    data: {
                        //post student_id and card_id
                        stuid: stu_id,
                        cardid: card_id
                    },
                    success: function(price){

                        $('#txt_price').val(price);

                    }
                });
            });
        });
    });


</script>